package com.eascs.web.o2o.web.controller;

import java.text.DecimalFormat;
import java.text.Format;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.eascs.app.dao.PageResult;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.common.util.UrlUtil;
import com.eascs.report.common.entity.BusiOperaForm;
import com.eascs.site.controller.BaseRestController;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.view.PaginationRestResult;
import com.eascs.site.view.ViewContext;
import com.eascs.web.o2o.web.service.BusiOperaService;

/**
 * 业务运营分析（贷后数据）
 * 工单：report-10331
 * @author:hzp
 * @date:2018年3月14日
*/
@RestController
@RequestMapping("/reportRest")
public class LoanAfterRestController extends BaseRestController{
	private static Logger logger = LoggerFactory.getLogger(LoanAfterController.class);
	@Autowired
	BusiOperaService boService;
	
	@RequestMapping("/busiOperate4loanAfter")
	public PaginationRestResult queryBO4LA(BusiOperaForm entity){
		logger.info("接口/reportRest/busiOperate4loanAfter入参:{}", JSON.toJSONString(entity));
		String o2ourl = "/reportRest/busiOperate4loanAfter";
	 		
 		if (entity != null) {
 			String loanDateStart = entity.getLoanDateStart() == null ? null : entity.getLoanDateStart();
 			String loanDateEnd = entity.getLoanDateEnd() == null ? null : entity.getLoanDateEnd();
 			String province = entity.getProvince() == null ? null : entity.getProvince();
 			String bankLoan = entity.getBankLoan() == null ? null : entity.getBankLoan();
 			o2ourl = UrlUtil.appendUrl(o2ourl, "loanDateStart", loanDateStart);
 			o2ourl = UrlUtil.appendUrl(o2ourl, "loanDateEnd", loanDateEnd);
 			o2ourl = UrlUtil.appendUrl(o2ourl, "province", province);
 			o2ourl = UrlUtil.appendUrl(o2ourl, "bankLoan", bankLoan);
 			o2ourl = o2ourl + "&pageIndex=";
 		} else {
 			o2ourl = o2ourl + "?pageIndex=";
 		}
 		entity.setPageSize(50);
 		PageResult<Object[]> pageResult = boService.getLoanAfter(entity);
 		
 		String titles[] = {"贷款申请单号","省区", "区域总监","信贷经理","信贷经理入职时间","放款银行","贷款类型","申请金额（万元）","终审金额（万元）","放款金额（万元）","放款日期","到期日期","是否续贷","借款人ID","借款人姓名","客户首次放款时间","客户所在省份","客户所在城市","客户所在区县"};
 		PaginationInfo o2oPagingInfo = new PaginationInfo(pageResult, titles, o2ourl);
 		o2oPagingInfo.setFormats(new Format[]{null, null, null, null, null, null,null,new DecimalFormat(",##0.00"),
				new DecimalFormat(",##0.00"),new DecimalFormat(",##0.00"), null, null, null, null, null, null, null, null});
 		o2oPagingInfo.setBuildPagingNavigation(true);
 		o2oPagingInfo.setFirstRenderColumnIndex(0);
 		o2oPagingInfo.setBuildRowNumber(true);
 		o2oPagingInfo.setBuildPagingNavigation(true);
 		o2oPagingInfo.setRendTo("#business_data");
 		ViewContext.put("vo", entity);
 		//ViewContext.put("o2ourl", o2ourl);
 		return PaginationRestResult.buildPaginationRestResult(o2oPagingInfo);	
	}
}
